package string;

import java.util.Arrays;

public class SplitDemo {
    public static void main(String[] args) {
        String line = "abc123def456ghi";
        String[] data = line.split("[0-9]+");//按数字拆分(数字就拆没了)
        System.out.println(Arrays.toString(data));//[abc,def,ghi]

        line = "123.456.78";
        data = line.split("\\.");//按.拆,就拆没了)
        System.out.println(Arrays.toString(data));//[123 456 78]
        //最开始就是拆分项,那么数组第一个元素为空字符串
        //如果连续两个(两个以上)可拆分项,那么中间也会拆出一个空字符串
        //如果末尾连续多个可拆分项,那么拆分的空字符串被忽略(不要的)
        line = "=123=456==78=====";
        data = line.split("=");//按= 拆(=就拆没了)
        System.out.println(Arrays.toString(data));//[ ,123,456, ,78]
        System.out.println(data.length);//5

    }
}
